package com.itheima.reggie.controller;

import com.itheima.reggie.common.PageResult;
import com.itheima.reggie.common.R;
import com.itheima.reggie.entity.Category;
import com.itheima.reggie.entity.Employee;
import com.itheima.reggie.service.CategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@RequestMapping("/category")
@Slf4j
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    @PostMapping
    public R<String> save(@RequestBody Category category){
        return categoryService.save(category);
    }

    @GetMapping("/page")
    public R<PageResult> findPage(@RequestParam(name = "page", defaultValue = "1") Long page, @RequestParam(name = "pageSize", defaultValue = "1") Long pageSize) {
        return categoryService.findPage(page, pageSize);
    }

    @PutMapping
    public R<String> update(@RequestBody Category category){
        long id = Thread.currentThread().getId();
        log.debug("*****************EmployeeController************线程id为{}**",id);
        return categoryService.update(category);
    }

    @DeleteMapping
    public R<String> deleteById(@RequestParam("id") Long id){
        return categoryService.deleteById(id);
    }

    /**
     * 菜品分类
     * @param category
     * @return
     */
    @GetMapping("/list")
    public R<List<Category>> list(Category category){
        return categoryService.list(category);
    }
}